﻿using sBlog.Net.Domain.Entities;
using HtmlAgilityPack;


namespace sBlog.Net.Models
{
    public class PostModel
    {
        public PostEntity Post { get; set; }
        public bool DisqusEnabled { get; set; }
        public string RootUrl { get; set; }

        private HtmlAgilityPack.HtmlDocument _doc;


        private HtmlAgilityPack.HtmlDocument Doc
        {
            get
            {
                if (_doc == null)
                {
                    _doc = new HtmlAgilityPack.HtmlDocument();
                    _doc.LoadHtml(this.Post.PostContent);
                }
                return _doc;
            }
        }

        public string PostTitle
        {
            get
            {
                HtmlNode node = this.Doc.DocumentNode.SelectSingleNode("//div[@class='postTitle']");
                if (node != null)
                {
                    return node.OuterHtml;
                }
                return "Заголовок поста не определён";
            }
        }
        
    }    
}
